home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / StereoScope / Source / AzimuthMat.m < prev    next >
Text File  |  1994-04-01  |  3KB  |  151 lines

  1. #import "AzimuthMat.h"
  2. #import "math.h"
  3. #import <string.h>
  4.  
  5. @implementation AzimuthMat
  6.  
  7. +new
  8. {
  9.   self = [super new];
  10.   limits[0] = limits[1] = limits[2] = 0.;
  11.   limits[3] = limits[4] = limits[5] = 1.;
  12.   [self reset];
  13.   phi = s_phi = 0.; c_phi = 1.0;
  14.   dist = 2.0;
  15.   [self setTheta:0.];
  16.   return self;
  17. }
  18.  
  19. +newLimits:(float *)newlimits
  20. {
  21.   register short int n = 6;
  22.   register float *lim;
  23.  
  24.   self = [super new];
  25.   lim = limits;
  26.   while(n--) *lim++ = *newlimits++;
  27.   [self reset];
  28.   phi = s_phi = 0.; c_phi = 1.0;
  29.   dist = 2.0;
  30.   [self setTheta:0.];
  31.   return self;
  32. }
  33.  
  34. -reset
  35. {
  36.   [super reset];
  37.   [self translate :-(limits[0] + limits[3]) / 2
  38.         :-(limits[1] + limits[4]) / 2
  39.         :-(limits[2] + limits[5]) / 2];
  40.   [self scale :1. / (limits[3] - limits[0])
  41.             :1. / (limits[4] - limits[1])
  42.             :1. / (limits[5] - limits[2])];
  43.   [self x_rotation_cs :0. :-1.];
  44.   memmove(to_theta_cache, mat, 16*sizeof(float));
  45.   is_cached_to_theta = YES;
  46.   return self;
  47. }
  48.  
  49. -setlimits:(float *)newlimits
  50. {
  51.   register short int n = 6;
  52.   register float *lim;
  53.  
  54.   lim = limits;
  55.   while(n--) *lim++ = *newlimits++;
  56.   [self reset];
  57.   return self;
  58. }
  59.  
  60. -setTheta:(float)radians
  61. {
  62.   if (is_cached_to_theta)
  63.     memmove(mat, to_theta_cache, 16*sizeof(float));
  64.   else {
  65.     [self reset];
  66.     memmove(to_theta_cache, mat, 16*sizeof(float));
  67.     is_cached_to_theta = YES;
  68.   }
  69.   is_cached_to_phi = is_cached_to_dist = NO;
  70.   theta = radians;
  71.   [self y_rotation_cs:(c_theta = cos(radians)) :(s_theta = sin(radians))];
  72.   [self x_rotation_cs:c_phi :s_phi];
  73.   [self perspective:dist];
  74.   return self;
  75. }
  76.  
  77. -setPhi:(float)radians
  78. {
  79.   if (is_cached_to_phi)
  80.     memmove(mat, to_phi_cache, 16*sizeof(float));
  81.   else {
  82.     if (is_cached_to_theta)
  83.       memmove(mat, to_theta_cache, 16*sizeof(float));
  84.     else
  85.       [self reset];
  86.     [self y_rotation_cs:c_theta:s_theta];
  87.     memmove(to_phi_cache, mat, 16*sizeof(float));
  88.     is_cached_to_phi = YES;
  89.   }
  90.   is_cached_to_dist = NO;
  91.   phi = radians;
  92.   [self x_rotation_cs:(c_phi = cos(radians)) :(s_phi = sin(radians))];
  93.   [self perspective:dist];
  94.   return self;
  95. }
  96.  
  97. -setdist:(float)distance
  98. {
  99.   if (is_cached_to_dist)
  100.     memmove(mat, to_dist_cache, 16*sizeof(float));
  101.   else {
  102.     if (is_cached_to_theta)
  103.       memmove(mat, to_theta_cache, 16*sizeof(float));
  104.     else
  105.       [self reset];
  106.     [self y_rotation_cs:c_theta:s_theta];
  107.     [self x_rotation_cs:c_phi:s_phi];
  108.     memmove(to_dist_cache, mat, 16*sizeof(float));
  109.     is_cached_to_dist = YES;
  110.   }
  111.   dist = distance;
  112.   [self perspective:dist];
  113.   return self;
  114. }
  115.  
  116. -setinvdist:(float)invdistance
  117. {
  118.   if (is_cached_to_dist)
  119.     memmove(mat, to_dist_cache, 16*sizeof(float));
  120.   else {
  121.     if (is_cached_to_theta)
  122.       memmove(mat, to_theta_cache, 16*sizeof(float));
  123.     else
  124.       [self reset];
  125.     [self y_rotation_cs:c_theta:s_theta];
  126.     [self x_rotation_cs:c_phi:s_phi];
  127.     memmove(to_dist_cache, mat, 16*sizeof(float));
  128.     is_cached_to_dist = YES;
  129.   }
  130.   if (invdistance == 0.) dist = HUGE;
  131.   else dist = 1./invdistance;
  132.   [self perspective_inv:invdistance];
  133.   return self;
  134. }
  135.  
  136. -(float)getTheta:sender;
  137. {
  138.   return theta;
  139. }
  140.  
  141. -(float)getPhi:sender;
  142. {
  143.   return phi;
  144. }
  145.  
  146. -(float)getdist:sender;
  147. {
  148.   return dist;
  149. }
  150.  
  151. @end